﻿@using Ubiety.Dns.Core

@{
    Layout = null;
}


<link href="~/layer-v3.1.1/layer-v3.1.1/layer/theme/default/layer.css" rel="stylesheet" />
<link href="~/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/layer-v3.1.1/layer-v3.1.1/layer/layer.js"></script>
<script src="~/layui/layui.all.js"></script>


<!--edit dialog start-->
<div class="site-text site-block">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名：</label>
            <div class="layui-input-block">
                <input type="text" name="UserName" id="UserName"  required lay-verify="required" placeholder="学生姓名" autocomplete="off" class="layui-input">
                <input type="text" name="Id" id="Id" value="@ViewBag.id " hidden="hidden">

            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">性别：</label>
            <div class="layui-input-block">
                <input type="radio" name="Sex" value="男" title="男">
                <input type="radio" name="Sex" value="女" title="女">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">电话：</label>
            <div class="layui-input-block">
                <input type="text" name="Phone" id="Phone" required lay-verify="required" placeholder="联系方式" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">爱好：</label>
            <div class="layui-input-block">
                <input type="text" name="Hobby" id="Hobby" required lay-verify="required" placeholder="个人爱好" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">描述：</label>
            <div class="layui-input-block">
                <textarea name="Description" id="Description" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">保存编辑</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--edit dialog end-->

<script>

    $(function () {
        var index = layer.msg('数据努力加载中...', { icon: 16, shade: 0.4, time: false });
        //数据初始化
        $.ajax({
            async: false,
            dataType: 'json',
            type: "post",
            data: { id: $("#Id").val() },
            url: "@Url.Action("QueryUserInfoDetail","OperationApi")",
            success: function (res) {
                layer.close(index);
                if (res.code == 0) {
                    var data = res.data;
                    console.log(data);
                    $("#UserName").val(data.userName);

                    //radio初始化
                    var rObj = document.getElementsByName("Sex");
                    for(var i = 0;i < rObj.length;i++){
                        if(rObj[i].value == data.sex){
                            rObj[i].checked = 'checked';
                        }
                    }
                    //$(":radio[name='Sex'][value='" + data.sex  + "']").prop("checked", "checked");

                    $("#Phone").val(data.phone);

                    $("#Hobby").val(data.hobby);

                    $("#Description").text(data.description);


                }
            }
        });

        layui.use('form', function(){
            var form = layui.form;
            form.render(); //更新全部


            //监听提交
            form.on('submit(formDemo)', function(data){
                //layer.msg(JSON.stringify(data.field));
                $.ajax({
                    async: true,
                    dataType: 'json',
                    type: 'post',
                    url: "@Url.Action("UpdateUserInfo","OperationApi")",
                    data:data.field,
                    success:function(res) {
                        //layer.msg(res);
                        console.log(res);
                        if (res.code == 0) {//successfully
                            layer.confirm(res.resultMsg, {
                                icon:1,
                                btn: ["我知道了"],
                                yes: function (index) {
                                    parent.location.href = "@Url.Action("Index")";
                                    parent.layer.closeAll();//关闭全部
                                }
                            });
                        } else {
                            layer.msg(res.resultMsg);
                        }
                    }
                });
                return false;
            });
        });
    });


</script>